<template>
  <div>
    <table class="table table-bordered">
      <tbody>
        <tr>
          <td>序号</td>
          <td>医生姓名</td>
          <td>头像</td>
          <td>科室</td>
          <td>创建日期</td>
        </tr>
        <tr v-for="a in info.list">
          <td>{{ a.yid }}</td>
          <td>{{ a.yname }}</td>
          <td><img :src="a.yimg" width="60" height="60" /></td>
          <td>{{ a.kname }}</td>
          <td>{{ moment(a.ytime).format("YYYY-MM-DD HH:mm:ss") }}</td>
        </tr>
      </tbody>
    </table>
  </div>
  <span><input type="button" value="首页" @click="page(1)" /></span>
  <span
    ><input type="button" value="上一页" @click="page(date.pageindex - 1)"
  /></span>
  <span
    ><input type="button" value="下一页" @click="page(date.pageindex + 1)"
  /></span>
  <span
    ><input type="button" value="尾页" @click="page(info.totalpage)"
  /></span>
</template>

<script setup lang="ts">
import axios from "axios";
import { reactive, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
import moment from "moment";
const route = useRoute();
const router = useRouter();
let info: any = reactive({
  list: [],
  totalpage: 0,
  totalcount: 0,
});
let date: any = reactive({
  pageindex: 1,
  pagesize: 2,
});
onMounted(() => {
  list();
});
const list = () => {
  axios({
    url: "/api/Yesheng/GetYesheng",
    method: "get",
    params: date,
  }).then((res) => {
    console.log(res);
    Object.assign(info, res.data);
  });
};
const page = (num: any) => {
  if (num < 1) {
    date.pageindex = 1;
    return;
  } 
   if (num > info.totalpage) {
    date.pageindex = info.totalpage;
    return;
  }
  date.pageindex = num;
  list();
};
</script>

<style scoped>
span {
  margin: 0 10px;
}
</style>
